import { Injectable } from '@angular/core';
import {FrameContext,BindingData,Repository} from '@farris/devkit';
import { BefRepository, ResponseInfo } from '@farris/bef';
import {  BeActionService, FormMessageService } from '@farris/command-services';
import { tap } from 'rxjs/operators';

@Injectable()
export class SbssLuStandMultSelectFrmControllerService {
  constructor(
        private frameContext: FrameContext,
        private beActionService: BeActionService,
        private messageService: FormMessageService
  ) {}

  /**
   * 选择点击事件
   * @remarks 
   * @returns 
   */
  toolBarItemClick(): any {
    let ids = this.frameContext.uiState['plandIds']

    let dataGrid = this.frameContext.appContext.componentManager.get(['sbssLuStandMultSelect-u687-component_sbsslustandmultselect_data-grid-component','dataGrid'])
    let standIds = dataGrid.checkeds.map(i=>i.id)

    const repository = this.frameContext.repository as BefRepository<any>;
    const requestInfo = repository.restService.buildRequestInfo();
    const actionUri = 'addstandtoplan';

    const body = {
      requestInfo: requestInfo,
      planIds:ids,
      standIds:standIds
    }

    const action$ = this.beActionService.invokeAction(actionUri, 'PUT', null, null, body);
    return action$.pipe(
      tap((responseInfo: ResponseInfo) => {
        this.messageService.info('批量添加成功!');
      }))

  }
}
